package com.hzy.yiyaoba.bean;

import java.util.ArrayList;
import java.util.List;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.hzy.yiyaoba.utils.Config;
import com.hzy.yiyaoba.utils.Config.LoreConfig;
import com.lidroid.xutils.http.RequestParams;

//"title":"嘴唇竟是身体健康晴雨表 自查可保命",
//"img":"img/lore/20150617183016_2.png",
//"count":68,
//"fcount":0,
//"rcount":0,
//"author":"yi18.net",
//"loreclass":5,
//"className":"女性保养",
//"md":"b4476d71d2f41f6991ef49f9775849d2",
//"time":"Jun 17, 2015 6:30:15 PM",
//"id":21548

public class Lore {
	private int id;
	private String title;
	private String img;
	private int count;
	private int fCount;
	private int rCount;
	private String author;
	private int loreClass;
	private String className;
	private String md;
	private String time;

	public Lore(int id, String title, String img, int count, int fCount, int rCount, String author, int loreClass, String className, String md, String time) {
		this.id = id;
		this.title = title;
		this.img = img;
		this.count = count;
		this.fCount = fCount;
		this.rCount = rCount;
		this.author = author;
		this.loreClass = loreClass;
		this.className = className;
		this.md = md;
		this.time = time;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getImg() {
		return img;
	}

	public void setImg(String img) {
		this.img = img;
	}

	public int getCount() {
		return count;
	}

	public void setCount(int count) {
		this.count = count;
	}

	public int getfCount() {
		return fCount;
	}

	public void setfCount(int fCount) {
		this.fCount = fCount;
	}

	public int getrCount() {
		return rCount;
	}

	public void setrCount(int rCount) {
		this.rCount = rCount;
	}

	public String getAuthor() {
		return author;
	}

	public void setAuthor(String author) {
		this.author = author;
	}

	public int getLoreClass() {
		return loreClass;
	}

	public void setLoreClass(int loreClass) {
		this.loreClass = loreClass;
	}

	public String getClassName() {
		return className;
	}

	public void setClassName(String className) {
		this.className = className;
	}

	public String getMd() {
		return md;
	}

	public void setMd(String md) {
		this.md = md;
	}

	public String getTime() {
		return time;
	}

	public void setTime(String time) {
		this.time = time;
	}

	public static RequestParams createRequestParams(int page, int limit, String type, int id) {
		RequestParams params = new RequestParams();
		params.addBodyParameter(LoreConfig.KEY_PAGE, String.valueOf(page));
		params.addBodyParameter(LoreConfig.KEY_LIMIT, String.valueOf(limit));
		params.addBodyParameter(LoreConfig.KEY_TYPE, type);
		params.addBodyParameter(LoreConfig.KEY_ID, String.valueOf(id));
		return params;
	}

	public static List<Lore> parseLoreList(String json) throws Exception {
		List<Lore> list = new ArrayList<Lore>();
		JSONObject obj = JSON.parseObject(json);
		if (!obj.getBoolean(Config.JSON_SUCCESS)) {
			return null;
		}
		JSONArray arr = obj.getJSONArray(Config.JSON_CONTENT);
		for (int i = 0; i < arr.size(); i++) {
			obj = arr.getJSONObject(i);

			int id = obj.getInteger(LoreConfig.JSON_ID);
			String title = obj.getString(LoreConfig.JSON_TITLE);
			String img = Config.URL_PIC_PRIX + obj.getString(LoreConfig.JSON_IMG);
			int count = obj.getInteger(LoreConfig.JSON_COUNT);
			int fCount = obj.getInteger(LoreConfig.JSON_FCOUNT);
			int rCount = obj.getInteger(LoreConfig.JSON_RCOUNT);
			String author = obj.getString(LoreConfig.JSON_AUTHOR);
			int loreClass = obj.getInteger(LoreConfig.JSON_LORE_CLASS);
			String className = obj.getString(LoreConfig.JSON_CLASS_NAME);
			String md = obj.getString(LoreConfig.JSON_MD);
			String time = obj.getString(LoreConfig.JSON_TIME);

			list.add(new Lore(id, title, img, count, fCount, rCount, author, loreClass, className, md, time));
		}
		return list;
	}

}
